package com.yangxk.kadmin.web.module.system.controller;

import com.yangxk.kadmin.common.beans.Result;
import com.yangxk.kadmin.web.module.system.form.DeptForm;
import com.yangxk.kadmin.web.module.system.po.Dept;
import com.yangxk.kadmin.web.module.system.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("/tree")
    public Result queryDeptTree() {
        return Result.ofSuccess(deptService.queryDeptTree());
    }

    @PostMapping("/add")
    public Result addDept(@RequestBody DeptForm deptForm) {
        deptService.addDept(deptForm);
        return Result.ofSuccess();
    }

    @PostMapping("/update")
    public Result editDept(@RequestBody DeptForm deptForm) {
        deptService.updateDept(deptForm);
        return Result.ofSuccess();
    }

    @GetMapping("/delete")
    public Result deleteDept(long id) {
        deptService.deleteDept(id);
        return Result.ofSuccess();
    }

    @GetMapping("/info")
    public Result<Dept> queryById(long id) {
        return Result.ofSuccess(deptService.selectByPrimaryKey(id));
    }
}
